﻿package mortal.game.utils
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.global.*;
    import extend.language.*;
    import flash.utils.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.view.copy.groupCopy.data.*;
    import mortal.game.view.task.data.*;
    import mortal.mvc.core.*;

    public class CopyUtil extends Object
    {

        public function CopyUtil()
        {
            return;
        }// end function

        public static function get isInCopy() : Boolean
        {
            return Cache.instance.copy.copyInfo != null && !MapFileUtil.isInCrossNormalMap;
        }// end function

        public static function get isShowBossKilledMap() : Boolean
        {
            if (Cache.instance.guild.isInGuild)
            {
                return false;
            }
            if (isInCopy)
            {
                return true;
            }
            return false;
        }// end function

        public static function getBattlefieldMapId() : int
        {
            return CopyConfig.instance.getCopyInfoByCode(GameConst.BattleFieldCopyCode).intoMapId;
        }// end function

        public static function getGuildWarMapId() : int
        {
            return CopyConfig.instance.getCopyInfoByCode(GameConst.GuildWarCopyCode).intoMapId;
        }// end function

        public static function get escortCopyMapId() : int
        {
            return CopyConfig.instance.getCopyInfoByCode(301).intoMapId;
        }// end function

        public static function get sunbathMapMapId() : int
        {
            return CopyConfig.instance.getCopyInfoByCode(130).intoMapId;
        }// end function

        public static function get WineMapId() : int
        {
            return CopyConfig.instance.getCopyInfoByCode(304).intoMapId;
        }// end function

        public static function get TreasureHuntMapId() : int
        {
            return CopyConfig.instance.getCopyInfoByCode(305).intoMapId;
        }// end function

        public static function get SixBossMapId() : int
        {
            return CopyConfig.instance.getCopyInfoByCode(150).intoMapId;
        }// end function

        public static function get AutoArenaMapId() : int
        {
            return CopyConfig.instance.getCopyInfoByCode(142).intoMapId;
        }// end function

        public static function get HeroArenaMapId() : int
        {
            return CopyConfig.instance.getCopyInfoByCode(163).intoMapId;
        }// end function

        public static function get HeroArenaRestRoomMapId() : int
        {
            return CopyConfig.instance.getCopyInfoByCode(162).intoMapId;
        }// end function

        public static function get guildBossMapId() : int
        {
            return CopyConfig.instance.getCopyInfoByCode(302).intoMapId;
        }// end function

        public static function isPetBreakCopyMapId(param1:int) : Boolean
        {
            return CopyConfig.instance.getCopyInfoByCode(113).maps.indexOf(param1.toString()) != -1;
        }// end function

        public static function isTowerCopyMapId(param1:int) : Boolean
        {
            return CopyConfig.instance.getCopyInfoByCode(131).maps.indexOf(param1.toString()) != -1 || CopyConfig.instance.getCopyInfoByCode(132).maps.indexOf(param1.toString()) != -1;
        }// end function

        public static function isGroupTowerCopyMapId(param1:int) : Boolean
        {
            return CopyConfig.instance.getCopyInfoByCode(146).maps.indexOf(param1.toString()) != -1 || CopyConfig.instance.getCopyInfoByCode(147).maps.indexOf(param1.toString()) != -1 || CopyConfig.instance.getCopyInfoByCode(148).maps.indexOf(param1.toString()) != -1 || CopyConfig.instance.getCopyInfoByCode(149).maps.indexOf(param1.toString()) != -1;
        }// end function

        public static function isArenaCopyMapId(param1:int) : Boolean
        {
            return CopyConfig.instance.getCopyInfoByCode(115).maps.indexOf(param1.toString()) != -1 || CopyConfig.instance.getCopyInfoByCode(144).maps.indexOf(param1.toString()) != -1 || CopyConfig.instance.getCopyInfoByCode(145).maps.indexOf(param1.toString()) != -1;
        }// end function

        public static function isHeroArenaCopyMapId(param1:int) : Boolean
        {
            return CopyConfig.instance.getCopyInfoByCode(163).maps.indexOf(param1.toString()) != -1 || CopyConfig.instance.getCopyInfoByCode(164).maps.indexOf(param1.toString()) != -1;
        }// end function

        public static function get isInDefenseCopy() : Boolean
        {
            return isInCopy && (Cache.instance.copy.copyInfo.group == 112 || Cache.instance.copy.copyInfo.group == 128);
        }// end function

        public static function get isInGroupDefenseCopy() : Boolean
        {
            return isInCopy && Cache.instance.copy.copyInfo.group == 138;
        }// end function

        public static function get isInGuildDefenseCopy() : Boolean
        {
            return isInCopy && Cache.instance.copy.copyInfo.type == ECopyType._ECopyTypeGuildDefense;
        }// end function

        public static function get isInTeamDefenseCopy() : Boolean
        {
            return isInCopy && Cache.instance.copy.copyInfo.group == 138;
        }// end function

        public static function get isInGuideDefenseCopy() : Boolean
        {
            return isInCopy && Cache.instance.copy.copyInfo.code == 128;
        }// end function

        public static function isDefenseCopyMapId(param1:int) : Boolean
        {
            return CopyConfig.instance.isDefenseCopyMapId(param1);
        }// end function

        public static function isHoleBossCopyMapId(param1:int) : Boolean
        {
            return CopyConfig.instance.getCopyInfoByCode(912).intoMapId == param1 || CopyConfig.instance.getCopyInfoByCode(913).intoMapId == param1;
        }// end function

        public static function get jlmdCopyMapId() : int
        {
            return CopyConfig.instance.getCopyInfoByCode(203).intoMapId;
        }// end function

        public static function get questionCopyMapId() : int
        {
            return CopyConfig.instance.getCopyInfoByCode(127).intoMapId;
        }// end function

        public static function getEscortCopyCarNum(param1:Dictionary) : Object
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_2:Array = [];
            var _loc_5:int = 0;
            while (_loc_5 <= EColor._EColorOrange)
            {
                
                _loc_3 = param1[_loc_5];
                _loc_2.push(_loc_3);
                _loc_4 = _loc_4 + _loc_3;
                _loc_5++;
            }
            return {arr:_loc_2, total:_loc_4};
        }// end function

        public static function get isInJLMD() : Boolean
        {
            var _loc_1:* = Cache.instance.copy.copyInfo;
            if (_loc_1 != null && _loc_1.code == 203)
            {
                return true;
            }
            return false;
        }// end function

        public static function get isInAHSW() : Boolean
        {
            var _loc_1:* = Cache.instance.copy.copyInfo;
            if (_loc_1 != null && _loc_1.code == 202)
            {
                return true;
            }
            return false;
        }// end function

        public static function get isInChallengeCopy() : Boolean
        {
            var _loc_1:* = Cache.instance.copy.copyInfo;
            if (_loc_1 && _loc_1.type == ECopyType._ECopyTypeChallenge)
            {
                return true;
            }
            return false;
        }// end function

        public static function get isQuestionCopy() : Boolean
        {
            var _loc_1:* = Cache.instance.copy.copyInfo;
            if (_loc_1 && _loc_1.type == ECopyType._ECopyTypeQuestion)
            {
                return true;
            }
            return false;
        }// end function

        public static function get isInGuildWarCopy() : Boolean
        {
            var _loc_1:* = Cache.instance.copy.copyInfo;
            if (_loc_1 != null && _loc_1.code == GameConst.GuildWarCopyCode)
            {
                return true;
            }
            return false;
        }// end function

        public static function get isInBattlefieldCopy() : Boolean
        {
            var _loc_1:* = Cache.instance.copy.copyInfo;
            if (_loc_1 != null && _loc_1.code == GameConst.BattleFieldCopyCode)
            {
                return true;
            }
            return false;
        }// end function

        public static function get isInGuildBossCopy() : Boolean
        {
            var _loc_1:* = Cache.instance.copy.copyInfo;
            if (_loc_1 != null && _loc_1.type == ECopyType._ECopyTypeGuildBoss)
            {
                return true;
            }
            return false;
        }// end function

        public static function get isInZZXYBattleCopy() : Boolean
        {
            var _loc_1:* = Cache.instance.copy.copyInfo;
            if (_loc_1 != null && _loc_1.code == GameConst.ZZXYBattleCopyId)
            {
                return true;
            }
            return false;
        }// end function

        public static function get isInSixBossCopy() : Boolean
        {
            var _loc_1:* = Cache.instance.copy.copyInfo;
            if (_loc_1 != null && _loc_1.code == GameConst.SixBossCopyCode)
            {
                return true;
            }
            return false;
        }// end function

        public static function needShowLeaveBtn(param1:TCopy) : Boolean
        {
            var _loc_2:* = (param1.quickQuit & 1) == 1;
            if (param1.type == ECopyType._ECopyTypeCross)
            {
                _loc_2 = false;
            }
            if (param1.type == ECopyType._ECopyTypeGuildManor && Cache.instance.guild.isInSelfGuild)
            {
                _loc_2 = true;
            }
            return _loc_2;
        }// end function

        public static function needHideTaskTrace(param1:TCopy) : Boolean
        {
            if (param1 == null)
            {
                return false;
            }
            if ((param1.quickQuit & 2) == 2)
            {
                return false;
            }
            return true;
        }// end function

        public static function needQuitDirectly(param1:TCopy) : Boolean
        {
            return (param1.quickQuit & 4) == 4;
        }// end function

        public static function needAutoFight(param1:TCopy) : Boolean
        {
            if (param1 == null)
            {
                return false;
            }
            return (param1.quickQuit & 8) == 8;
        }// end function

        public static function needHideActiveIcons(param1:TCopy) : Boolean
        {
            return (param1.quickQuit & 16) == 16;
        }// end function

        public static function get isHasNomalEscortTask() : Boolean
        {
            var _loc_2:TaskInfo = null;
            var _loc_1:* = Cache.instance.task.getTaskByGroupInTaskDoing(ETaskGroup._ETaskGroupEscort);
            if (_loc_1 && _loc_1.length)
            {
                _loc_2 = _loc_1[0] as TaskInfo;
                return _loc_2.isDoing() || _loc_2.isFail();
            }
            return false;
        }// end function

        public static function get isInNomalEscortTask() : Boolean
        {
            var _loc_2:TaskInfo = null;
            var _loc_1:* = Cache.instance.task.getTaskByGroupInTaskDoing(ETaskGroup._ETaskGroupEscort);
            if (_loc_1 && _loc_1.length)
            {
                _loc_2 = _loc_1[0] as TaskInfo;
                return _loc_2 && _loc_2.isDoing();
            }
            return false;
        }// end function

        public static function get isInAllEscortTask() : Boolean
        {
            return Cache.instance.task.isInEscortTask();
        }// end function

        public static function get isCanOpenGuildDefenseCopy() : Boolean
        {
            if (!GuildConst.hasPermissions(GuildConst.OpenDefenceCopy))
            {
                return false;
            }
            if (Cache.instance.guild.selfGuildInfo.baseInfo.level < 2)
            {
                return false;
            }
            if (Cache.instance.copy.guildDefence.isOpenCopy)
            {
                return false;
            }
            if (Global.isDebugModle)
            {
                return true;
            }
            var _loc_1:* = ClockManager.instance.nowDate;
            return true;
        }// end function

        public static function copyCheck(param1:Function, ... args) : void
        {
            args = null;
            if (Cache.instance.group.isInCopyGroup)
            {
                args = new GroupCopyLeaveOperData();
                args.callBack = param1;
                args.prame = args;
                Dispatcher.dispatchEvent(new DataEvent(EventName.GroupLeave, args));
            }
            else if (CopyUtil.isInAllEscortTask)
            {
                MsgManager.showRollTipsMsg(Language.getString(20687), MsgRollTipsType.msgRollTips3);
            }
            else if (!GameController.arena.isInArena && (GameController.arena.isMatching || GameController.arena.isMatchSucc))
            {
                args = new GroupCopyLeaveOperData();
                args.callBack = param1;
                args.prame = args;
                Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaEnterCopyOnMatch, args));
            }
            else if (!GameController.copy.heroArenaCopy.isInArena && (GameController.copy.heroArenaCopy.isMatching || GameController.copy.heroArenaCopy.isMatchSucc))
            {
                args = new GroupCopyLeaveOperData();
                args.callBack = param1;
                args.prame = args;
                Dispatcher.dispatchEvent(new DataEvent(EventName.HeroArenaEnterCopyOnMatch, args));
            }
            else
            {
                param1.apply(null, args);
            }
            return;
        }// end function

        public static function get isInGroupCopy() : Boolean
        {
            return Cache.instance.group.isInCopyGroup && Cache.instance.group.isTeamMateInCopy;
        }// end function

        public static function get isInPlacardCopy() : Boolean
        {
            var _loc_1:* = Cache.instance.copy.copyInfo;
            if (_loc_1 == null)
            {
                return false;
            }
            if (_loc_1.type == ECopyType._ECopyTypeHeavenPlacard || _loc_1.type == ECopyType._ECopyTypeEarthPlacard)
            {
                return true;
            }
            return false;
        }// end function

        public static function get isInNotAutoOutCopy() : Boolean
        {
            if (isInGuildBossCopy)
            {
                return true;
            }
            if (isInZZXYBattleCopy)
            {
                return true;
            }
            if (isInPlacardCopy)
            {
                return true;
            }
            return false;
        }// end function

        public static function get isInMainCityBattleKOCopy() : Boolean
        {
            if (Cache.instance.copy.copyInfo == null)
            {
                return false;
            }
            if (Cache.instance.copy.copyInfo.type == ECopyType._ECopyTypeMainCityBattle)
            {
                return true;
            }
            return false;
        }// end function

        public static function get isInMainCityBattleFinalCopy() : Boolean
        {
            if (Cache.instance.copy.copyInfo == null)
            {
                return false;
            }
            if (Cache.instance.copy.copyInfo.type == ECopyType._ECopyTypeMainCityBattel2)
            {
                return true;
            }
            return false;
        }// end function

    }
}
